﻿// <copyright file="TerrainFeaturesPlayer.cs" company="Gravity Age Studios">
// Code released under the MIT license (see License.txt).
// </copyright>
// <author>Vicente Cartas Espinel</author>
// <email>vicente.cartas@gmail.com</email>
namespace LightSwitchApplication
{
    using System;
    using System.Windows.Controls;
    using Microsoft.LightSwitch.Presentation;
    using Microsoft.LightSwitch.Presentation.Extensions;

    public partial class TerrainFeaturesPlayer
    {
        #region View TerrainFeature

        partial void ViewDetails_CanExecute(ref bool result)
        {
            result = this.Collection.SelectedItem != null;
        }

        partial void ViewDetails_Execute()
        {
            this.OpenModalWindow("ModalWindow");
            this.FindControl("ModalWindow").ControlAvailable += new EventHandler<ControlAvailableEventArgs>(ModalWindow_ControlAvailable);
            this.FindControl("PublicInformation").IsVisible = this.Collection.SelectedItem.HasPublicInformation;
        }

        partial void SubmitModalWindow_Execute()
        {
            this.CloseModalWindow("ModalWindow");
        }

        #endregion

        #region Helper Methods

        private void ModalWindow_ControlAvailable(object sender, ControlAvailableEventArgs e)
        {
            ChildWindow window = (ChildWindow)e.Control;
            window.Closed += new EventHandler(window_Closed);
        }

        private void window_Closed(object sender, EventArgs e)
        {
            ChildWindow window = (ChildWindow)sender;
            if (!(window.DialogResult.HasValue && window.DialogResult.Value))
            {
                window.Closed -= window_Closed;
            }
        }

        #endregion
    }
}
